/* eslint-disable */

export default function initCocos(ops,cb) {
    // <canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="0"></canvas>
    // const canvas_id = "GameCanvas";
    // let canvas = document.createElement("canvas");
    // canvas.id = canvas_id;
    // document.body.appendChild(canvas);

    // 判断是否初始化过了
    if(cc.game._prepared){
            if(cb){
                cb();
            }
       return; 
    }

    var settings = {
        platform: "web-mobile",
        groupList: [
            "default"
        ],
        collisionMatrix: [
            [
                true
            ]
        ],
        hasResourcesBundle: false,
        hasStartSceneBundle: false,
        remoteBundles: [],
        subpackages: [],
        // launchScene: "db://assets/main.fire",
        orientation: "",
        debug: true,
        jsList: []
    };

    var options = {
        id: "GameCanvas",
        debugMode: cc.debug.DebugMode.INFO,
        showFPS: true,
        frameRate: 30,
        groupList: ['default'],
        collisionMatrix: settings.collisionMatrix,
        ...ops,
    };

    cc.assetManager.init({ 
        bundleVers: settings.bundleVers,
        remoteBundles: settings.remoteBundles,
        server: settings.server
    });

    cc.assetManager.loadBundle(cc.AssetManager.BuiltinBundleName.INTERNAL, (err)=>{
        if (err) return console.error(err.message, err.stack);
        cc.game.run(options, function() {
            cc.view.enableRetina(true);
            // cc.view.enableAntiAlias(true);
            cc.view.resizeWithBrowserSize(true);

            if(cb){
                cb();
            }
        });
    });
}
